package com.example.a0529liuhongzhi.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.example.a0529liuhongzhi.R;
import com.example.a0529liuhongzhi.lhz.Account;
import com.example.a0529liuhongzhi.lhz.Account;

import java.util.List;

public class ListViewAdapter extends BaseAdapter {
    List<Account> accounts;
    Context context;

    public ListViewAdapter(List<Account> accounts, Context context) {
        this.accounts = accounts;
        this.context = context;
    }

    public ListViewAdapter(List<Account> accounts, FragmentActivity activity) {
    }

    @Override
    public int getCount() {
        return accounts!=null?accounts.size():0;
    }

    @Override
    public Object getItem(int i) {
        return accounts.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.listview_layout,null);
        }
        Account account=accounts.get(i);
        ImageView imageView;
        TextView autor,price;
        imageView=view.findViewById(R.id.image);
        autor=view.findViewById(R.id.autor);
        price=view.findViewById(R.id.price);
        imageView.setImageResource(account.getImageId());
        autor.setText(account.getName());
        price.setText(account.getPrice()+"");
        return view;
    }
}
